﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using DM_Article.Model;
using DM_Article.Bll;

public partial class admin_admin_bigclassadd : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["username"] == null)
            {
                Response.Write("<script language='javascript'>alert('非法操作，请先登录！');location.href = 'admin_login.aspx';</script>");
            }
            else if (!checkUserType(Session["username"].ToString()))
            {
                Response.Write("<script language='javascript'>alert('权限不足！');location.href = 'admin_bigclass.aspx';</script>");
            }
        }
    }

    //权限管理
    private bool checkUserType(string username)
    {
        using (OleDbConnection cn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionStringAccess"].ConnectionString))
        {
            cn.Open();
            admin adn = adminbll.getAdminDetailByName(cn, username);
            return (adn.usertype == "0" || adn.usertype == "1");
        }
    }

    protected void btn_bigclassadd_Click(object sender, EventArgs e)
    {
        using (OleDbConnection cn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionStringAccess"].ConnectionString))
        {
            cn.Open();
            string bigclassname = this.txtbigclassname.Text.Trim();
            if (bigclassname == "")
            {
                Response.Write("<script language='javascript'>alert('请先填写大类名称');</script>");
                this.txtbigclassname.Focus();
            }
            else
            {
                bigclass bc = new bigclass();
                bc.bigclassname = bigclassname;
                if (bigclassbll.add(cn, bc) > 0)
                {
                    Response.Write("<script language='javascript'>alert('添加成功！');location.href = 'admin_bigclassadd.aspx';</script>");
                }
                else
                {
                    Response.Write("<script language='javascript'>alert('添加失败！');location.href = 'admin_bigclassadd.aspx';</script>");
                }
            }
        }
    }
    protected void btn_back_Click(object sender, EventArgs e)
    {
        Response.Redirect("admin_bigclass.aspx");
    }
}
